//
//  OrderFooter.m
//  HMMarket
//
//  Created by 孙鹏飞 on 2017/5/10.
//  Copyright © 2017年 homai. All rights reserved.
//

#import "OrderFooter.h"

@interface OrderFooter ()

@property (weak, nonatomic) IBOutlet UIButton *confirmGoodBtn;

@property (weak, nonatomic) IBOutlet UIButton *cancleBtn;

@property (weak, nonatomic) IBOutlet UIButton *goPayBtn;

@property (weak, nonatomic) IBOutlet UIButton *completedBtn;

@property (weak, nonatomic) IBOutlet UIButton *returnGoodBtn;

@property (weak, nonatomic) IBOutlet UIButton *returnOfBtn; // 退货中

@property (weak, nonatomic) IBOutlet UIButton *returnOkBtn; // 退货完成


@end

@implementation OrderFooter

+ (instancetype)orderFooter
{
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    [self configBtn:_confirmGoodBtn];
    [self configBtn:_goPayBtn];
    [self configBtn:_completedBtn];
    [self configBtn:_returnGoodBtn];
    [self configBtn:_returnOfBtn];
    [self configBtn:_returnOkBtn];
    [self configBtn:_cancleBtn];
}

- (void)configBtn:(UIButton *)btn
{
    btn.layer.borderColor = kMainColor.CGColor;
    btn.layer.borderWidth = 1;
    btn.layer.cornerRadius = 17;
    btn.layer.masksToBounds = YES;
}

- (void)setModel:(OrderModel *)model
{
    _model = model;
//    NSLog(@"pay_status -- >%@",_model.pay_status);
//    NSLog(@"post_status -- >%@",_model.post_status);
    
  if ([_model.pay_status isEqualToString:@"0"]&&[_model.post_status isEqualToString:@"2"]) {
      // 代付款
      _confirmGoodBtn.hidden = YES;
      _goPayBtn.hidden = NO;
      _completedBtn.hidden = YES;
      _cancleBtn.hidden = YES;
      
      
      if ([_model.return_order isEqualToString:@"1"]) {
          _returnGoodBtn.hidden = YES;
          _returnOfBtn.hidden = NO;
          _returnOkBtn.hidden = YES;
      } else if ([_model.return_order isEqualToString:@"2"]) {
          _returnGoodBtn.hidden = YES;
          _returnOfBtn.hidden = YES;
          _returnOkBtn.hidden = NO;
      } else {
          _returnGoodBtn.hidden = NO;
          _returnOfBtn.hidden = YES;
          _returnOkBtn.hidden = YES;
      }
      
    } else if ([model.pay_status isEqualToString:@"0"]&&[model.post_status isEqualToString:@"1"]) {
        // 待收货
        _confirmGoodBtn.hidden = NO;
        _goPayBtn.hidden = YES;
        _completedBtn.hidden = YES;
        
        if ([_model.return_order isEqualToString:@"1"]) {
            _returnGoodBtn.hidden = YES;
            _returnOfBtn.hidden = NO;
            _returnOkBtn.hidden = YES;
            _cancleBtn.hidden = YES;
        } else if ([_model.return_order isEqualToString:@"2"]) {
            _returnGoodBtn.hidden = YES;
            _returnOfBtn.hidden = YES;
            _returnOkBtn.hidden = NO;
            _cancleBtn.hidden = YES;
        } else {
            _returnGoodBtn.hidden = NO;
            _returnOfBtn.hidden = YES;
            _returnOkBtn.hidden = YES;
            _cancleBtn.hidden = NO;
        }
        
    } else {
        _confirmGoodBtn.hidden = YES;
        _goPayBtn.hidden = YES;
        _completedBtn.hidden = NO;
        _returnGoodBtn.hidden = YES;
        _returnOfBtn.hidden = YES;
        _returnOkBtn.hidden = YES;
        _cancleBtn.hidden = YES;
    }
}

- (IBAction)confirmGoodBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedConfirmGoodBtn:)]) {
        [_delegate OrderFooter:self didClickedConfirmGoodBtn:_model];
    }
}


- (IBAction)goPayBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedGoPayBtn:)]) {
        [_delegate OrderFooter:self didClickedGoPayBtn:_model];
    }
}

- (IBAction)CompletedBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedCompletedBtnBtn:)]) {
        [_delegate OrderFooter:self didClickedCompletedBtnBtn:_model];
    }
}


- (IBAction)returnGoodBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedReturnGoodBtn:)]) {
        [_delegate OrderFooter:self didClickedReturnGoodBtn:_model];
    }
}

- (IBAction)returnOfBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedReturnOfBtn:)]) {
        [_delegate OrderFooter:self didClickedReturnOfBtn:_model];
    }
}

- (IBAction)returnOkBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedReturnOkBtn:)]) {
        [_delegate OrderFooter:self didClickedReturnOkBtn:_model];
    }
}

- (IBAction)cancleBtnClick:(id)sender {
    if ([_delegate respondsToSelector:@selector(OrderFooter:didClickedCancleBtn:)]) {
        [_delegate OrderFooter:self didClickedCancleBtn:_model];
    }
}



@end
